<?php

App::uses('AppController', 'Controller');

class ContactController extends AppController {

    public $helpers = array('Html');

    public function beforeFilter() {
        parent::beforeFilter();
    }

    public function index() {
        $this->loadModel('Settings');
        $description = $this->Settings->findByKey('contact_description');
        $img = $this->Settings->findByKey('contact_img');
        $map = $this->Settings->findByKey('contact_map');       
        
        if ($description)
            $this->set('description', $description);
        if ($img)
            $this->set('img', $img);
        if ($map)
            $this->set('map', $map);
        
        if ($this->request->is('post')) {
            $this->Contact->create();
            if ($this->Contact->save($this->request->data)) {
                $result =array('status' => 1, 'message' => 'Your message has been sent. Thank you!');
                echo json_encode($result);
                die();
                //$this->Session->setFlash(__('Your feedback has been saved.'), 'default', array(), 'good');
                //return $this->redirect(array('action' => 'index'));
            } else {
                $result =array('status' => 0, 'message' => 'Can not sent your message, plz try again!');
                echo json_encode($result);
                die();
                //$this->Session->setFlash(__('Cannot save your feedback.'), 'default', array(), 'bad');
            }
        }
    }

}
